package com.proxy.scanandcheck.scaner.controller;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.proxy.scanandcheck.common.valueobject.ProxyRequest;
import com.proxy.scanandcheck.scaner.thread.ScannerThreadPool;

@Service
@Scope("singleton")
public class ScannerController {
	
	private Future<Boolean> result = null;
	
	@Autowired
	private ScannerThreadPool scannerThreadPool;
	
	public void process(final ProxyRequest proxyRequest)
	{
		ExecutorService executorService = Executors.newSingleThreadExecutor();
		
		Callable<Boolean> task = new Callable<Boolean>() {
			public Boolean call() throws Exception {
				
				return scannerThreadPool.execute(proxyRequest);
			}
		};
		
		result = executorService.submit(task);
	}

	public boolean isThreadRunning() {
		return this.result != null && !this.result.isDone();
	}

}
